package com.xm.factory;

/**
 * 简单工厂模式
 */
public class ASimple {
    public static void main(String[] args) {
        ShapeFactory factory = new ShapeFactory();
        Shape circle = ShapeFactory.getShape("circle");
        circle.draw();
    }
}

interface Shape{
    void draw();
}

class Circle implements Shape {
    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}

class Rectangle implements Shape {
    @Override
    public void draw() {
        System.out.println("绘制矩形");
    }
}

//简单工厂类
class ShapeFactory {
    public static Shape getShape(String type) {
        if("circle".equalsIgnoreCase(type)) {
            return new Circle();
        } else if ("rectangle".equalsIgnoreCase(type)) {
            return new Rectangle();
        }
        throw new IllegalArgumentException("未知形状类型：" + type);
    }
}